<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<link rel="Bookmark" href="favicon.ico" >
	<link rel="Shortcut Icon" href="favicon.ico" />
	<!--[if lt IE 9]>
	<script type="text/javascript" src="/public/lib/html5.js"></script>
	<script type="text/javascript" src="/public/lib/respond.min.js"></script>
	<![endif]-->
	<link rel="stylesheet" type="text/css" href="/public/static/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="/public/static/h-ui.admin/css/H-ui.admin.css" />
	<link rel="stylesheet" type="text/css" href="/public/lib/Hui-iconfont/1.0.8/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="/public/static/h-ui.admin/skin/default/skin.css" id="skin" />
	<link rel="stylesheet" type="text/css" href="/public/static/h-ui.admin/css/style.css" />
	<!--[if IE 6]>
	<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
	<script>DD_belatedPNG.fix('*');</script>
	<![endif]-->
	<title></title>
	<meta name="keywords" content="洛阳易购商城">
	<meta name="description" content="洛阳易购商城">
</head>
<body>
<article class="cl pd-20">
	<div class="form form-horizontal">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>导航标题：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" autocomplete="off" value="{$adv_list['adv_title']}" placeholder="幻灯片标题" class="input-text" id="adv_title" name="adv_title">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>导航分类：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<select id="cate_id" onchange="cate_url(this.value)" class="form-control m-b input-common">
					<option value="-1">请选择..</option>
					{volist name="list" id="vo"}
					<option value="{$vo['cate_id']}" {if condition="$adv_list.cate_id==$vo.cate_id"} selected {/if}>{$vo['cate_name']}</option>
					{/volist}
				</select>
			</div>
		</div>
		<div class="lie_1">
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>导航图片：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<p style="height: 165px;width:165px;border: dashed 1px #e5e5e5">
						<img src="/{$adv_list['adv_image']}" alt="" id="imgbrand_pic" class="thumbnail">
					</p>
					<div class="upload-btn">
					<span>
						<input name="file_upload" style="display: none" id="uploadImg" type="file" onchange="imgUpload(this);">
						<input type="hidden" value="{$adv_list['adv_image']}" id="brand_pic" />
					</span>
						<input class="btn radius btn-secondary" onclick="on_upload()" type="button" value="上传图片">
					</div>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>链接地址：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" autocomplete="off" value="{$adv_list['adv_url']}" placeholder="链接地址" class="input-text" id="adv_url" name="adv_url">
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>排序：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input id="sort" type="number" placeholder="排序" value="{$adv_list['sort']}" class="input-text">
			</div>
		</div>
		<input type="hidden" id="adv_id" value="{$adv_id}">
		<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input class="btn btn-primary radius" onclick="addAdvertAjax()" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
		</div>
		</div>
	</div>
</article>
<script src="/public/menu/js/jquery-2.1.1.js"></script>
<script type="text/javascript" src="/public/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/public/static/h-ui/js/H-ui.js"></script>
<script src="/public/static/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="/public/static/js/file_upload.js" type="text/javascript"></script>
<script type="text/javascript">
function on_upload() {
    $("#uploadImg").click();
}
function cate_url(id) {
    if (id=='-1'){
        $("#adv_url").val('');
    }else {
        $("#adv_url").val("{$Think.SHOP_GOODS_CATE}"+id);
    }
}
//广告位图片上传
function imgUpload(event) {
    var fileid = $(event).attr("id");
    var str = $(event).next().attr("id");
    var data = { 'file_path' : "advert/" };
    uploadFile(fileid,data,function(res){
        if(res.code){
            $("#img"+str).attr("src",res.data);
            $("#"+str).val(res.data);
            layer.msg(res.message,{icon:1,time:1000});
        }else{
            layer.msg(res.message,{icon:1,time:1000});
        }
    });
}
function addAdvertAjax() {
    var adv_id = $("#adv_id").val();
    var adv_title = $("#adv_title").val();
    var adv_image = $("#brand_pic").val();
    var adv_url = $("#adv_url").val();
    var sort = $("#sort").val();
    var background = $("#background").val();
    var cate_id = $("#cate_id").val();
    if(verify(adv_title,cate_id,adv_image,adv_url,sort)){
        $.ajax({
            type : "post",
            url : "{:url('advert/editNavigation')}",
            data : {
                'adv_id' : adv_id,
                'adv_title' : adv_title,
				'cate_id':cate_id,
                'adv_image' : adv_image,
                'adv_url' : adv_url,
                'sort' : sort,
                'background' : background,
            },
            success : function(data) {
                if (data["code"] > 0) {
                    layer.msg('添加成功!',{icon:1,time:1000},function () {
                        window.parent.location.reload();
                    });
                }else{
                    layer.msg('添加失败',{icon:5,time:1000});
                }
            }
        });
    }
}
function verify(adv_title,cate_id,adv_image,adv_url,sort){
       if(adv_title == ''){
           layer.msg('请输入名称',{icon:5,time:1000});
           $('#adv_title').focus();
           return false;
       }
    if(cate_id == '-1'){
        layer.msg('请选择分类',{icon:5,time:1000});
        $('#cate_id').focus();
        return false;
    }
       if(adv_image == ''){
           layer.msg('请上传图片',{icon:5,time:1000});
           return false;
       }
       if(adv_url == ''){
           layer.msg('请填写链接',{icon:5,time:1000});
           $("#adv_url").focus();
           return false;
       }
		if(sort == ''){
            layer.msg('请填写位置排序',{icon:5,time:1000});
			$("#sort").focus();
			return false;
		}
    return true;
}
</script>
</body>
</html>